<!DOCTYPE html>
<html lang="">
<head>
    <meta charset="utf-8">
    <title>{$page_info.title}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    {include file="common/header" /}
</head>
<body>

<div class="layui-padding-2">
    <div class="layui-card layui-panel">
        <div class="layui-padding-2">
            <div class="layui-form" >
                <input type="hidden" name="id" value="{$info.id}">
                <div class="layui-form-item">
                    <label class="layui-form-label">角色名称</label>
                    <div class="layui-input-block layui-input-wrap">
                        <input type="text" name="name" lay-verify="required" placeholder="请输入角色名称" autocomplete="off" class="layui-input" value="{$info.name}">
                        <div class="layui-form-mid layui-text-em" style="float: none;">为角色指定一个名称</div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">角色状态</label>
                    <div class="layui-input-block layui-input-wrap">
                        <input type="radio" name="status" value="1" title="正常" {if($info.status == '1')}checked{/if}>
                        <input type="radio" name="status" value="2" title="封禁" {if($info.status == '2')}checked{/if}>
                        <div class="layui-form-mid layui-text-em" style="float: none;">角色的状态</div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">超级权限</label>
                    <div class="layui-input-block layui-input-wrap">
                        <input type="checkbox" name="conditions" title="所有权" value="{$auth_super}" {if($info.conditions == $auth_super)}checked{/if}>
                        <div class="layui-form-mid layui-text-em" style="float: none;">勾选后，此角色拥有所有权</div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">角色权限</label>
                    <div class="layui-input-block layui-input-wrap">
                        <div id="tree-container"></div>
                        <div class="layui-form-mid layui-text-em" style="float: none;">为角色分配拥有的权限</div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn sys_submit" lay-submit lay-filter="{$table_id}_submit">立即提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="__ADMINS__component/layui/layui.js"></script>
<script src="__ADMINS__component/pear/pear.js"></script>

<script>
    layui.use(['form','toast', 'popup'], function() {
        var $ = layui.$;
        var form = layui.form;
        var toast = layui.toast;
        var popup = layui.popup;
        var tree = layui.tree;

        var data_s = {$rule|raw};
        tree.render({
            elem: '#tree-container' // 绑定元素
            ,data: data_s // 树形结构的数据
            ,showCheckbox: true // 显示复选框
            ,id: 'id' // 节点id
            ,isJump: false // 是否启用点击节点跳转
        });
        form.on('submit({$table_id}_submit)', function(data){
            var field = data.field; // 获取表单字段值
            // var checkedData = tree.getChecked('id');
            // field['rule_data'] = checkedData;
            $.post('{:url($operate.update)}',field,function(res){
                if(res.code === 200){
                    popup.success(res.msg, function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    });
                }else{
                    toast.error({
                        message: res.msg,
                    });
                }
            })
            return false;
        });
        form.render();
    })
</script>
</body>
</html>